home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
capit1.exe
/
CAPIT.C
next >
Wrap
C/C++ Source or Header
|
1992-06-24
|
25KB
|
595 lines
// ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
// █ █
// █ module: capit.c █
// █ written by: David Harris [dh] █
// █ abstract: This module duplicates the functionality of the █
// █ CAPTURE.EXE utility. █
// █ █
// █ environment: NetWare 2.15 - 3.11, NETX v3.22 or v3.26 █
// █ Borland C++ v3.0 or Microsoft C v6.0 █
// █ NetWare C Interface-DOS v1.2 █
// █ █
// █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
// █ maintenance history: █
// █ level date pi description █
// █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
// █ 001 03/24/92 dh initial release. █
// █ 002 06/15/92 dh Fixed setting of local printer device to █
// █ actual device instead of 0 █
// █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
// █ Disclaimer: █
// █ Novell, Inc. makes no representations or warranties with respect █
// █ to any NetWare software, and specifically disclaims any express █
// █ or implied warranties of merchantability, title, or fitness for █
// █ a particular purpose. █
// █ █
// █ Distribution of any NetWare software is forbidden without the █
// █ express written consent of Novell, Inc. Further, Novell █
// █ reserves the right to discontinue distribution of any NetWare █
// █ software. █
// █ █
// █ Novell is not responsible for lost profits or revenue, loss of █
// █ use of the software, loss of data, costs of re-creating lost █
// █ data, the cost of any substitute equipment or program, or claims █
// █ by any party other than you. Novell strongly recommends a █
// █ backup be made before any software is installed. Technical █
// █ support of this software may be provided at the discretion of █
// █ Novell. █
// ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "nit.h"
#include <niterror.h>
#ifdef __TURBOC__
#include <dir.h>
#else
#include <direct.h>
#endif
// Generic, non-compiler-specific macros to build and split far pointers
#define xMK_FP( seg,ofs )( (void _far * )((unsigned long)((unsigned long)(seg) << 16 ) +( unsigned long)( (ofs) & 0xFFFF )))
#define xFP_SEG( fp )((unsigned)( (unsigned long)(void far *)(fp) >> 16))
#define xFP_OFF( fp )(((unsigned)( (unsigned long)(void far *)(fp) & 0xFFFF)))
// Globals
char fsName[80], queueName[48];
BYTE majorVersion, minorVersion, revisionLevel, oldLPT;
WORD objectType, oldConnectionID;
CAPTURE_FLAGS setCaptureFlags;
CAPTURE_FLAGS getCaptureFlags;
// Prototypes
void usage(void);
void exitout(int);
void ShowSettings(void);
void main(int argc, char **argv)
{
int retCode = 0, count, count2;
char *tempArg;
char fileName[255], vName[16];
char dirName[255], VOLPath[255];
char objectName[48];
BYTE localPrinterToCaptureTo;
BYTE qSpecified = FALSE, capFile = FALSE;
BYTE loginTime[7];
WORD captureFileConnectionID, printServerConnectionID, serverNumber;
long objectID, queueID;
oldConnectionID = GetDefaultConnectionID();
oldLPT = localPrinterToCaptureTo = GetDefaultLocalPrinter();
if (argc>1)
{
if (argv[1][0]!='?')
{
// Get shell version to handle problems in certain shells
retCode = GetNetWareShellVersion(&majorVersion,
&minorVersion,
&revisionLevel);
if (retCode == 0)
{
printf("Shell version too old\n");
exit(1);
}
else
printf("Shell v%d.%02d", majorVersion, minorVersion);
if (revisionLevel > 0)
printf(" %c\n", revisionLevel + 'A' - 1);
else
printf("\n");
// Process the command line options so we know the LPT of concern right away
for (count=1; count<argc; count++)
{
if (argv[count][0] == '-' || argv[count][0]=='/')
argv[count]++; // Remove option prefix
if (toupper(argv[count][0]) == 'L')
{
if (argv[count][1] == '=')
localPrinterToCaptureTo = atoi(&argv[count][2]) - 1;
else
localPrinterToCaptureTo = atoi(&argv[count][1]) - 1;
if (localPrinterToCaptureTo >2)
{
printf("Device out of range: %s\n", localPrinterToCaptureTo+1);
exitout(1);
}
}
}
// Now that we know the LPT of concern, lets set up the default printer, etc.
SetDefaultLocalPrinter(localPrinterToCaptureTo);
GetDefaultCaptureFlags(&setCaptureFlags);
// If version 3.xx or higher shell, buffer pointers are no longer swapped,
// but the NetWare C Interface-DOS v1.2 swaps the incomming buffer, so fix it
if (majorVersion > 2)
{
setCaptureFlags.printerSetupBuffer =
(char far *)LongSwap((long)setCaptureFlags.printerSetupBuffer);
setCaptureFlags.printerResetBuffer =
(char far *)LongSwap((long)setCaptureFlags.printerResetBuffer);
}
queueID = setCaptureFlags.printQueueID;
retCode = GetLPTCaptureStatus(&serverNumber);
retCode = 0;
if (retCode == 0) // Reset flags if not currently captured
{
setCaptureFlags.status = 0x00;
setCaptureFlags.flags = 0x00;
setCaptureFlags.tabSize = 0x08;
setCaptureFlags.serverPrinter = 0x00;
setCaptureFlags.numberOfCopies = 0x01;
setCaptureFlags.formType = 0x00;
// Fixed 6/15/92, dh
// setCaptureFlags.localLPTDevice = 0x00;
setCaptureFlags.localLPTDevice = localPrinterToCaptureTo;
//
setCaptureFlags.flushCaptureTimeoutCount = 0x00;
setCaptureFlags.flushCaptureOnDeviceClose = FALSE;
setCaptureFlags.maxLines = 66;
setCaptureFlags.maxChars = 132;
setCaptureFlags.maxChars = 20;
setCaptureFlags.formName[0] = '\0';
setCaptureFlags.LPTCaptureFlag = FALSE;
setCaptureFlags.fileCaptureFlag = FALSE;
setCaptureFlags.printQueueFlag = FALSE;
setCaptureFlags.printQueueID = 0x00;
}
retCode = GetLPTCaptureStatus(&printServerConnectionID);
// Process the remainder of the command line options
for (count=1; count<argc; count++)
{
if (argv[count][0]=='-' || argv[count][0]=='/')
argv[count]++; // Remove option prefix
strupr(argv[count]);
tempArg = argv[count];
switch (argv[count][0])
{
case 'L': // Local port (got it earlier, thanks anyway)
break;
case 'S': // Options that begin with 'S'
++argv[count];
switch (argv[count][0])
{
case 'H': // Show settings
ShowSettings();
break;
default: // Server name
if (argv[count][0] == '=') ++argv[count];
retCode = GetConnectionID(argv[count], &printServerConnectionID);
if (retCode != 0)
{
printf("Error 0x%X getting connection ID for: %s\n",
retCode, argv[count]);
exitout(1);
}
// Check to make sure we are logged in, not just attached (we can get the queue
// id when attached, but we can only capture when we're logged in)
SetPreferredConnectionID(printServerConnectionID);
GetConnectionInformation(GetConnectionNumber(),
objectName, &objectType, &objectID, loginTime);
if (objectID == 0)
{
printf("Not logged into %s\n", argv[count]);
exitout(1);
}
SetPreferredConnectionID(oldConnectionID);
break;
}
break;
case 'Q': // Queue name
++argv[count];
if (argv[count][0] == '=') ++argv[count];
strncpy(queueName, argv[count], 47);
queueName[47] = '\0';
qSpecified = TRUE;
break;
case 'N': // Options that begin with 'N'
++argv[count];
switch (argv[count][0])
{
case 'A': // Options that begin with "NA"
++argv[count];
switch (argv[count][0])
{
case 'M': // User name
++argv[count];
if (argv[count][0] == '=') ++argv[count];
retCode = SetBannerUserName(argv[count]);
if (retCode != 0)
{
printf("Error setting banner name: %s\n", argv[count]);
exitout(1);
}
break;
default: // Auto endcap disabled
setCaptureFlags.flushCaptureOnDeviceClose = TRUE;
break;
}
break;
case 'B': // No banner
setCaptureFlags.flags = setCaptureFlags.flags & (~0x80);
for (count2=0; count2<13; count2++)
{
setCaptureFlags.bannerText[count2] = 0x00;
}
break;
case 'F': // No automatic form feed
setCaptureFlags.flags = setCaptureFlags.flags | 0x08;
break;
case 'N': // Options that begin with "NN"
++argv[count];
switch (argv[count][0])
{
case 'O': // Options that begin with "NNO"
++argv[count];
switch (argv[count][0])
{
case 'T': //No NOTify
setCaptureFlags.flags = setCaptureFlags.flags &
(~0x10);
break;
}
break;
}
case 'O': // Options that beging with "NO"
++argv[count];
switch (argv[count][0])
{
case 'T': // NOTify
setCaptureFlags.flags = setCaptureFlags.flags |
0x10;
break;
}
break;
case 'T': // No tab expansion
setCaptureFlags.flags = setCaptureFlags.flags & (~0x40);
break;
default:
printf("Invalid option:%s\n", tempArg);
break;
}
break;
case 'F': // Options that begin with 'F'
++argv[count];
switch (argv[count][0])
{
case 'F': // Automatic form feed
++argv[count];
setCaptureFlags.flags = setCaptureFlags.flags & (~0x08);
break;
default: // Form type
if (argv[count][0] == '=') ++argv[count];
if (isdigit(argv[count][0]))
setCaptureFlags.formType = atoi(argv[count]);
else
strcpy(setCaptureFlags.formName, argv[count]);
break;
}
break;
case 'T': // Options that begin with 'T'
++argv[count];
switch (argv[count][0])
{
case 'I': // Timeout
++argv[count];
if (argv[count][0] == '=') ++argv[count];
setCaptureFlags.flushCaptureTimeoutCount = IntSwap(atoi(argv[count])*18);
break;
default: // Tab expansion
if (argv[count][0] == '=') ++argv[count];
setCaptureFlags.flags = setCaptureFlags.flags | 0x40;
setCaptureFlags.tabSize = atoi(argv[count]);
break;
}
break;
case 'B': // Banner name
++argv[count];
if (argv[count][0] == '=') ++argv[count];
setCaptureFlags.flags = setCaptureFlags.flags | 0x80;
strncpy(setCaptureFlags.bannerText, argv[count], 12);
break;
case 'C': // Options that begin with 'C'
++argv[count];
switch(argv[count][0])
{
case 'R': // Create file
++argv[count];
if (argv[count][0] == '=') ++argv[count];
ConvertNameToFullPath(argv[count], VOLPath);
ParsePath(argv[count], fsName, vName, dirName);
retCode =
GetConnectionID(fsName, &captureFileConnectionID);
if (retCode != 0)
{
printf("Error 0x%X getting connection ID for capture file\n");
exitout(1);
}
strcpy(VOLPath, vName);
strcat(VOLPath, ":");
strcat(VOLPath, dirName);
// This path will be invalid if it was taken from a fake root
capFile = TRUE;
setCaptureFlags.fileCaptureFlag = TRUE;
break;
default: // # of copies
if (argv[count][0] == '=') ++argv[count];
setCaptureFlags.numberOfCopies = atoi(argv[count]);
break;
}
break;
case 'A': // Auto endcap enabled
++argv[count];
if (argv[count][0] == '=') ++argv[count];
setCaptureFlags.flushCaptureOnDeviceClose = FALSE;
break;
default:
printf("Invalid option: %s\n", tempArg);
break;
}
}
// End, Set, Start...must be in this order!
// End the current capture
EndLPTCapture();
// The LPTCaptureFlag must be cleared or else the shell will think the
// Queue ID belongs to the server that was being captured to previously.
if (capFile)
{
SetPreferredConnectionID(captureFileConnectionID);
retCode = SpecifyCaptureFile(0, VOLPath);
SetPreferredConnectionID(oldConnectionID);
if (retCode != 0)
{
printf("Error 0x%X capturing to : %s\n", retCode, fileName);
exitout(1);
}
}
// Which printer server are we talking to?
SetPreferredConnectionID(printServerConnectionID);
// Which queue are we sending to?
if (!capFile)
{
if (qSpecified)
{
retCode = GetBinderyObjectID(queueName, OT_PRINT_QUEUE,
&queueID);
if (retCode != 0)
{
printf("Error 0x%X getting object id for: %s\n", retCode,
argv[count]);
exitout(1);
}
}
setCaptureFlags.LPTCaptureFlag = FALSE;
retCode = SetCapturePrintQueue(localPrinterToCaptureTo,
printServerConnectionID, queueID);
if (retCode != 0)
{
printf("Error 0x%X setting print queue\n", retCode);
exitout(1);
}
}
// Set the flags, THEN start the capture...
retCode = SetDefaultCaptureFlags((SET_CAPTURE_FLAGS *)&setCaptureFlags);
if (retCode != 0)
{
printf("Error setting capture flags: 0x%X\n", retCode);
exitout(1);
}
// Start the capture
retCode = StartLPTCapture();
if (retCode != 0 && retCode != 255)
{
printf("Error starting capture: 0x%X\n", retCode);
exitout(1);
}
// Report to user what we just captured
GetDefaultCaptureFlags(&getCaptureFlags);
printf("Device LPT%d: re-routed to ", localPrinterToCaptureTo+1);
if (capFile)
printf("file %s on server %s\n", VOLPath, fsName);
else
{
GetFileServerName(printServerConnectionID, fsName);
if (getCaptureFlags.printQueueFlag)
{
GetBinderyObjectName(getCaptureFlags.printQueueID,
queueName, &objectType);
printf("queue %s ", queueName);
}
else
printf("printer %d ", getCaptureFlags.serverPrinter);
printf("on server %s.\n", fsName);
}
exitout(retCode);
}
else usage();
}
else usage();
}
/****************************************************************************
ShowSettings: Process /SH parameter by showing capture settings for each
printer
****************************************************************************/
void ShowSettings(void)
{
int count, retCode;
WORD currentConnectionID;
char temp[64];
// Check each printer port we can capture
for (count = 0; count < 3; count++)
{
printf("LPT%d: ", count + 1);
SetDefaultLocalPrinter(count);
retCode = GetLPTCaptureStatus(¤tConnectionID);
// Are we capturing?
if (retCode != 0)
{
GetDefaultCaptureFlags(&getCaptureFlags);
// If version 3.xx or higher shell, buffer pointers are no longer swapped,
// but the NetWare C Interface-DOS v1.2 swaps the incomming buffer
if (majorVersion > 2)
{
setCaptureFlags.printerSetupBuffer =
(char far *)LongSwap((long)setCaptureFlags.printerSetupBuffer);
setCaptureFlags.printerResetBuffer =
(char far *)LongSwap((long)setCaptureFlags.printerResetBuffer);
}
SetPreferredConnectionID(currentConnectionID);
GetFileServerName(currentConnectionID, fsName);
// Display what we're capturing to (server queue/file name)
printf("Capturing data to %s ", fsName);
if (getCaptureFlags.fileCaptureFlag)
printf("in a file.\n");
else
{
if (getCaptureFlags.printQueueFlag)
{
GetBinderyObjectName(getCaptureFlags.printQueueID,
queueName, &objectType);
printf("queue %s.\n", queueName);
}
else
printf("printer %d.\n", getCaptureFlags.serverPrinter);
}
// Will we notify the user when done?
printf(" Will %snotify user when job is printed.\n",
(getCaptureFlags.flags & 0x10) ? "" : "NOT ");
// Are we using capture defaults (not currently implemented)
printf(" Capture defaults: %-15s",
getCaptureFlags.status ? "Disabled" : "Enabled");
// Auto endcap when program goes back to DOS (or the LPT is closed)?
printf(" Automatic endcap: %-15s\n",
getCaptureFlags.flushCaptureOnDeviceClose ? "Disabled" : "Enabled");
// Display banner name/none if banner printing, no banner if no banner
printf(" Banner name : ");
if (getCaptureFlags.flags && 0x80)
if (getCaptureFlags.bannerText[0] == '\0')
printf("%-15s", "LPT:");
else
{
sprintf(temp, "\"%s\"", getCaptureFlags.bannerText);
printf("%-15s", temp);
}
else
printf("%-15s", "(no banner)");
// Do we send form feeds at the end of a job?
printf(" Form feeds : %-8s\n",
(getCaptureFlags.flags & 0x08) ? "Disabled" : "Enabled");
// How many copies?
printf(" Copies : %-15d",
getCaptureFlags.numberOfCopies);
// Are we expanding tabs?
printf(" Tabs : ");
if (getCaptureFlags.flags & 0x40)
printf("Converted to %d spaces\n",
getCaptureFlags.tabSize);
else
printf("Not converted\n");
// What form are we printing to?
printf(" Form : ");
sprintf(temp, "%02d (%s)", getCaptureFlags.formType,
(getCaptureFlags.formName[0] >= 32) ? getCaptureFlags.formName : "default");
printf("%-15s", temp);
// How soon do we assume the job is finished?
printf(" Timeout : ");
if (getCaptureFlags.flushCaptureTimeoutCount == 0)
printf("Disabled\n");
else
printf("%u seconds\n", IntSwap(getCaptureFlags.flushCaptureTimeoutCount)/18);
// Just for fun, where are the setup/reset buffers?
printf(" Setup buffer : %04X:%04X ",
xFP_SEG(LongSwap((long)getCaptureFlags.printerSetupBuffer)),
xFP_OFF(LongSwap((long)getCaptureFlags.printerSetupBuffer)));
printf(" Reset buffer : %04X:%04X\n",
xFP_SEG(LongSwap((long)getCaptureFlags.printerResetBuffer)),
xFP_OFF(LongSwap((long)getCaptureFlags.printerResetBuffer)));
}
else
printf("Capturing not currently active.\n");
}
SetDefaultLocalPrinter(oldLPT);
exitout(0);
}
/****************************************************************************
usage: Show usage for command line options
****************************************************************************/
void usage()
{
fprintf(stderr, "CAPIT v1.02x\n");
fprintf(stderr, "Usage:\n ");
fprintf(stderr, "CAPIT -<opt><param> [-<opt><param>]\n");
fprintf(stderr, " Where <opt> is one of the following:\n");
fprintf(stderr, " /SHow /Server=fileserver /Queue=queue name /Local=n\n");
fprintf(stderr, " /Form=form or n /CReate=path /Copies=n /TImeout=n /Tabs=n\n");
fprintf(stderr, " /No Tabs /Banner=bannername /NAMe=name /No Banner /FormFeed\n");
fprintf(stderr, " /No Form Feed /Autoendcap /No Autoendcap.\n\n");
fcloseall();
exitout(-1);
}
/****************************************************************************
exitout: Cleanup routine
****************************************************************************/
void exitout(int retCode)
{
if (oldConnectionID != 0)
SetPreferredConnectionID(oldConnectionID);
exit(retCode);
}